﻿using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Missbot.Common;

namespace Missbot.Admin.Filters
{
    public class ExceptionFilter : IExceptionFilter
    {
        private static ILogSvc ILogSvc => AutofacSvc.Resolve<ILogSvc>();
        
        public void OnException(ExceptionContext context)
        {
            ILogSvc.LogError(context.Exception, new {Path = context.HttpContext?.Request.Path.ToString()});
            context.ExceptionHandled = true;
            context.Result           = new StatusCodeResult((int) HttpStatusCode.InternalServerError);
        }
    }
}